package obj;

import game.GameWin;
import utils.GameUtils;

import java.awt.*;

public class RockObj extends GameObj{
    public RockObj(Image image, int x, int y, int width, int height, double speed, GameWin frame) {
        super(image, x, y, width, height, speed, frame);
    }

    @Override
    public void paintSelf(Graphics gImage) {
        super.paintSelf(gImage);
        y += speed;
        //陨石的越界消失，判断条件：y>600，改变后的坐标：（-600，600）
        if (y > 600) {
            this.x = -600;
            this.y = 600;
            GameUtils.removeList.add(this);
        }
        //陨石与我方飞机的碰撞检测
        if (this.getRec().intersects(this.frame.planeObj.getRec())) {
            GameWin.state = 3;
        }
        //陨石与我方子弹的碰撞检测
        for (ShellObj shellObj : GameUtils.shellObjList) {
            if (this.getRec().intersects(shellObj.getRec())) {
                shellObj.setX(-100);
                shellObj.setY(100);
                GameUtils.removeList.add(shellObj);
            }
        }
        //陨石与敌方飞机的碰撞检测
        for (EnemyObj enemyObj : GameUtils.enemyObjList) {
            if (this.getRec().intersects(enemyObj.getRec())) {
                ExplodeObj explodeObj = new ExplodeObj(x, y);
                GameUtils.explodeObjList.add(explodeObj);
                GameUtils.removeList.add(explodeObj);

                enemyObj.setX(-200);
                enemyObj.setY(200);
                GameUtils.removeList.add(enemyObj);
            }
        }
        //陨石与敌方子弹的碰撞检测
        for (BulletObj bulletObj : GameUtils.bulletObjList) {
            if (this.getRec().intersects(bulletObj.getRec())) {
                bulletObj.setX(-300);
                bulletObj.setY(300);
                GameUtils.removeList.add(bulletObj);
            }
        }
    }

    @Override
    public Rectangle getRec() {
        return super.getRec();
    }
}
